<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/22 9:23
 * Modified Time: 2019/7/22 9:23
 * Version: 2.0
 */

namespace App\Modules\MemberCard\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class GetMyReceiveMemberCardListCriteria extends BaseCriterias
{
    private $phone;

    public function __construct($phone)
    {
        $this->phone = $phone;
    }

    public function apply($model, RepositoryInterface $repository)
    {
        $mobile = $this->phone;

        $select = [
            'hx_member_card.id',
            'hx_card_type.name',
            'hx_card_type.id as card_type_id',
            'hx_store.name as store_name'
        ];
        $select = implode($select,',');
        $model = $model->selectRaw($select)
        ->where('member_id','=','0')
            ->leftJoin('card_type','member_card.type_id','card_type.id')
            ->leftJoin('store','card_type.store_id','store.id')
            ->where('mobile','=',$mobile)->orderBy('id','DESC')

        ;

        return $model;
    }
}